<!--考核项批复-->
<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>批复考核项</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form label-width="120px" ref="editForm">
          <el-form-item label="考核项：">
            {{ assessmentName }}
          </el-form-item>
          <el-form-item label="考核项资料：">
            <el-upload
                class="avatar-uploader"
                :action="$uploadImg"
                :show-file-list="false"
                :on-success="handleSuccess"
                accept=".doc,.docx,.xls,.xlsx,.rar,.zip,.7z,.jpg,.jpeg,.png,.mp4,.pdf"
                :before-upload="beforeAvatarUpload"
                v-if="!isExamine">
              <img v-if="pic" :src="pic" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
            <viewerModle type="1" :imgSrc="pic" v-else></viewerModle>
          </el-form-item>
          <el-form-item label="考核项评分：" prop="name">
            <el-radio-group v-model="is_examine" v-if="!isExamine">
              <el-radio :label="1">合格</el-radio>
              <el-radio :label="2">不合格</el-radio>
            </el-radio-group>
            <p v-else>{{ is_examine == 1 ? '合格' : '不合格' }}</p>
          </el-form-item>
          <el-form-item label="考核项批注：" prop="name">
            <el-input auto-complete="off" placeholder="考核项批注（不合格时需填写批注）" v-model="reason" v-if="!isExamine"></el-input>
            <p v-else>{{ reason ? reason : '无批注' }}</p>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button @click="submitFromFn" size="small" type="primary" v-if="!isExamine">确定并保存</el-button>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  props: ['visible', 'assessmentId', 'resumeId', 'assessmentName', 'isExamine'], // assessmentId 考核项id  resumeId 简历 id
  components: {},
  data() {
    return {
      dialogVisible: false,
      is_examine: 1, // 1通过2不通过
      reason: '',
      pic: '',// 资料
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        if (this.isExamine) {
          this.InitFn()
        }
      } else {
        this.pic = '';
        this.reason = '';
        this.is_examine = 1;
      }
    }
  },
  created() {

  },
  methods: {
    submitFromFn() {
      // 判断新增 编辑
      let dataOption = {
        id: this.assessmentId,// 	整型 	必填 	1 	- 	考核id
        material: JSON.stringify({pic: this.pic}),// 	整型 	必填 	1 	- 	资料
        is_examine: this.is_examine,// 	整型 	必填 	1 	- 	1通过2不通过
        reason: this.reason,// 	整型 	必填 	1 	- 	原因
      };
      this.$post(this.api.recruit.examine.examine, dataOption).then((response) => {
        if (!response.code) {
          this.$message.success(response.msg)
          this.$emit('InitFn')
          this.closePOpup()
        } else {
          this.$message.error(response.msg)
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    // 获取详情
    async InitFn() {
      let data = await this.$fetch(this.api.recruit.examine.edit, {id: this.assessmentId});
      if (!data.code) {
        this.is_examine = data.vo.is_examine
        this.reason = data.vo.reason
        this.pic = data.vo.material.pic
      } else {
        this.$message.error(data.msg)
      }
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    // 选择图片===============star
    handleSuccess(response) {
      this.pic = response.data.name
    },
    beforeAvatarUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < 2
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!')
      }
      return isLt2M
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 50%;
  height: 50%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
  z-index: 9;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}
</style>


